package com.ghq.controller;


import com.ghq.pojo.Result;
import com.ghq.pojo.User;
import com.ghq.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class LoginController {
    private final LoginService loginService;

    @Autowired
    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    @PostMapping("/login")
    public Result login(@RequestParam(name = "username") String username,
                        @RequestParam(name = "password") String password) {
        log.info("username:{},password:{}", username, password);
        User user = loginService.getUsernameAndPassword(username, password);
        return user != null?Result.success():Result.error("用户名或密码错误");
    }
}
